資料讀取

tar 讀取


In [1]:
import tarfile

In [2]:
# 檔案名稱格式
filename_format="M06A_{year:04d}{month:02d}{day:02d}.tar.gz".format
xz_filename_format="xz/M06A_{year:04d}{month:02d}{day:02d}.tar.xz".format
csv_format = "M06A/{year:04d}{month:02d}{day:02d}/{hour:02d}/TDCS_M06A_{year:04d}{month:02d}{day:02d}_{hour:02d}0000.csv".format

In [3]:
# 打開剛才下載的檔案試試
data_config ={"year":2016, "month":12, "day":18}
tar = tarfile.open(filename_format(**data_config), 'r')

In [4]:
# 如果沒有下載,可以試試看 xz 檔案
#data_dconfig ={"year":2016, "month":11, "day":18}
#tar = tarfile.open(xz_filename_format(**data_config), 'r')

In [5]:
# 列出內容
tar.list()


?rwxrwxrwx nobody/nobody          0 2016-12-19 06:31:22 M06A/20161218/ 
?rwxr-xr-x nobody/nobody          0 2016-12-19 06:31:22 M06A/20161218/19/ 
?rw-r--r-- nobody/nobody   43788302 2016-12-19 06:58:57 M06A/20161218/19/TDCS_M06A_20161218_190000.csv 
?rwxr-xr-x nobody/nobody          0 2016-12-19 06:31:21 M06A/20161218/13/ 
?rw-r--r-- nobody/nobody   47797413 2016-12-19 06:58:52 M06A/20161218/13/TDCS_M06A_20161218_130000.csv 
?rwxr-xr-x nobody/nobody          0 2016-12-19 06:31:22 M06A/20161218/21/ 
?rw-r--r-- nobody/nobody   34892056 2016-12-19 06:58:58 M06A/20161218/21/TDCS_M06A_20161218_210000.csv 
?rwxr-xr-x nobody/nobody          0 2016-12-19 06:31:17 M06A/20161218/00/ 
?rw-r--r-- nobody/nobody   10242555 2016-12-19 06:58:46 M06A/20161218/00/TDCS_M06A_20161218_000000.csv 
?rwxr-xr-x nobody/nobody          0 2016-12-19 06:31:20 M06A/20161218/07/ 
?rw-r--r-- nobody/nobody   29010414 2016-12-19 06:58:48 M06A/20161218/07/TDCS_M06A_20161218_070000.csv 
?rwxr-xr-x nobody/nobody          0 2016-12-19 06:31:21 M06A/20161218/14/ 
?rw-r--r-- nobody/nobody   56223075 2016-12-19 06:58:53 M06A/20161218/14/TDCS_M06A_20161218_140000.csv 
?rwxr-xr-x nobody/nobody          0 2016-12-19 06:31:20 M06A/20161218/10/ 
?rw-r--r-- nobody/nobody   48228393 2016-12-19 06:58:50 M06A/20161218/10/TDCS_M06A_20161218_100000.csv 
?rwxr-xr-x nobody/nobody          0 2016-12-19 06:31:22 M06A/20161218/22/ 
?rw-r--r-- nobody/nobody   23328529 2016-12-19 06:58:59 M06A/20161218/22/TDCS_M06A_20161218_220000.csv 
?rwxr-xr-x nobody/nobody          0 2016-12-19 06:31:20 M06A/20161218/09/ 
?rw-r--r-- nobody/nobody   44472646 2016-12-19 06:58:49 M06A/20161218/09/TDCS_M06A_20161218_090000.csv 
?rwxr-xr-x nobody/nobody          0 2016-12-19 06:31:20 M06A/20161218/03/ 
?rw-r--r-- nobody/nobody    4482391 2016-12-19 06:58:47 M06A/20161218/03/TDCS_M06A_20161218_030000.csv 
?rwxr-xr-x nobody/nobody          0 2016-12-19 06:31:20 M06A/20161218/04/ 
?rw-r--r-- nobody/nobody    6234003 2016-12-19 06:58:47 M06A/20161218/04/TDCS_M06A_20161218_040000.csv 
?rwxr-xr-x nobody/nobody          0 2016-12-19 06:31:21 M06A/20161218/17/ 
?rw-r--r-- nobody/nobody   51941166 2016-12-19 06:58:55 M06A/20161218/17/TDCS_M06A_20161218_170000.csv 
?rwxr-xr-x nobody/nobody          0 2016-12-19 06:31:21 M06A/20161218/15/ 
?rw-r--r-- nobody/nobody   59027318 2016-12-19 06:58:54 M06A/20161218/15/TDCS_M06A_20161218_150000.csv 
?rwxr-xr-x nobody/nobody          0 2016-12-19 06:31:20 M06A/20161218/06/ 
?rw-r--r-- nobody/nobody   17867508 2016-12-19 06:58:47 M06A/20161218/06/TDCS_M06A_20161218_060000.csv 
?rwxr-xr-x nobody/nobody          0 2016-12-19 06:31:18 M06A/20161218/01/ 
?rw-r--r-- nobody/nobody    6568696 2016-12-19 06:58:46 M06A/20161218/01/TDCS_M06A_20161218_010000.csv 
?rwxr-xr-x nobody/nobody          0 2016-12-19 06:31:21 M06A/20161218/12/ 
?rw-r--r-- nobody/nobody   40639579 2016-12-19 06:58:51 M06A/20161218/12/TDCS_M06A_20161218_120000.csv 
?rwxr-xr-x nobody/nobody          0 2016-12-19 06:31:21 M06A/20161218/18/ 
?rw-r--r-- nobody/nobody   44388617 2016-12-19 06:58:56 M06A/20161218/18/TDCS_M06A_20161218_180000.csv 
?rwxr-xr-x nobody/nobody          0 2016-12-19 06:31:22 M06A/20161218/20/ 
?rw-r--r-- nobody/nobody   41976533 2016-12-19 06:58:57 M06A/20161218/20/TDCS_M06A_20161218_200000.csv 
?rwxr-xr-x nobody/nobody          0 2016-12-19 06:31:21 M06A/20161218/16/ 
?rw-r--r-- nobody/nobody   56768259 2016-12-19 06:58:55 M06A/20161218/16/TDCS_M06A_20161218_160000.csv 
?rwxr-xr-x nobody/nobody          0 2016-12-19 06:31:20 M06A/20161218/05/ 
?rw-r--r-- nobody/nobody   10337717 2016-12-19 06:58:47 M06A/20161218/05/TDCS_M06A_20161218_050000.csv 
?rwxr-xr-x nobody/nobody          0 2016-12-19 06:31:19 M06A/20161218/02/ 
?rw-r--r-- nobody/nobody    4735396 2016-12-19 06:58:46 M06A/20161218/02/TDCS_M06A_20161218_020000.csv 
?rwxr-xr-x nobody/nobody          0 2016-12-19 06:31:20 M06A/20161218/08/ 
?rw-r--r-- nobody/nobody   37158659 2016-12-19 06:58:48 M06A/20161218/08/TDCS_M06A_20161218_080000.csv 
?rwxr-xr-x nobody/nobody          0 2016-12-19 06:31:20 M06A/20161218/11/ 
?rw-r--r-- nobody/nobody   44919062 2016-12-19 06:58:51 M06A/20161218/11/TDCS_M06A_20161218_110000.csv 
?rwxr-xr-x nobody/nobody          0 2016-12-19 06:31:22 M06A/20161218/23/ 
?rw-r--r-- nobody/nobody   12896245 2016-12-19 06:58:59 M06A/20161218/23/TDCS_M06A_20161218_230000.csv 

In [6]:
# 打開裡面 10 點鐘的資料
csv = tar.extractfile(csv_format(hour=10, **data_config))
# 類似檔案的物件
csv


Out[6]:
<ExFileObject name='M06A_20161218.tar.gz'>

In [7]:
# 印出前十行來看看
for i in range(10):
    print(csv.readline().decode())


31,2016-12-18 10:00:50,01F1045N,2016-12-18 10:29:01,01F0584N,53.400,Y,2016-12-18 10:00:50+01F1045N; 2016-12-18 10:04:37+01F0979N; 2016-12-18 10:05:58+01F0956N; 2016-12-18 10:07:43+01F0928N; 2016-12-18 10:10:43+01F0880N; 2016-12-18 10:18:38+01F0750N; 2016-12-18 10:27:26+01H0608N; 2016-12-18 10:29:01+01F0584N

31,2016-12-18 10:34:24,01F3525S,2016-12-18 10:46:09,01F3686S,20.200,Y,2016-12-18 10:34:24+01F3525S; 2016-12-18 10:37:13+01F3561S; 2016-12-18 10:39:21+01F3590S; 2016-12-18 10:42:54+01F3640S; 2016-12-18 10:45:26+01F3676S; 2016-12-18 10:46:09+01F3686S

31,2016-12-18 10:57:33,03F3854N,2016-12-18 11:15:23,01F3686S,33.600,Y,2016-12-18 10:57:33+03F3854N; 2016-12-18 11:12:29+01F3640S; 2016-12-18 11:14:45+01F3676S; 2016-12-18 11:15:23+01F3686S

31,2016-12-18 10:05:11,03F0525S,2016-12-18 10:07:39,03F0559S,12.100,Y,2016-12-18 10:05:11+03F0525S; 2016-12-18 10:07:39+03F0559S

31,2016-12-18 10:35:46,01F3185S,2016-12-18 11:05:08,01F3686S,54.100,Y,2016-12-18 10:35:46+01F3185S; 2016-12-18 10:38:12+01F3227S; 2016-12-18 10:39:37+01F3252S; 2016-12-18 10:41:30+01F3286S; 2016-12-18 10:46:13+01F3366S; 2016-12-18 10:47:57+01F3398S; 2016-12-18 10:51:34+01F3460S; 2016-12-18 10:57:54+01F3561S; 2016-12-18 10:59:37+01F3590S; 2016-12-18 11:04:35+01F3676S; 2016-12-18 11:05:08+01F3686S

31,2016-12-18 10:00:35,03F3496N,2016-12-18 10:03:32,03F3445N,16.800,Y,2016-12-18 10:00:35+03F3496N; 2016-12-18 10:03:32+03F3445N

32,2016-12-18 10:00:21,05F0287N,2016-12-18 12:40:50,03F0021N,46.600,Y,2016-12-18 10:00:21+05F0287N; 2016-12-18 12:27:33+05F0055N; 2016-12-18 12:31:28+05F0001N; 2016-12-18 12:32:17+03F0150N; 2016-12-18 12:32:53+03F0140N; 2016-12-18 12:34:24+03F0116N; 2016-12-18 12:38:33+03F0054N; 2016-12-18 12:40:50+03F0021N

31,2016-12-18 10:50:12,01H0271N,2016-12-18 10:55:02,01H0200N,13.300,Y,2016-12-18 10:50:12+01H0271N; 2016-12-18 10:54:30+01H0208N; 2016-12-18 10:55:02+01H0200N

31,2016-12-18 10:09:36,01F0339S,2016-12-18 10:16:15,01H0447S,19.400,Y,2016-12-18 10:09:36+01F0339S; 2016-12-18 10:16:15+01H0447S

32,2016-12-18 10:36:58,01F3696N,2016-12-18 10:43:35,01F3640N,8.000,Y,2016-12-18 10:36:58+01F3696N; 2016-12-18 10:38:24+01F3676N; 2016-12-18 10:43:35+01F3640N

利用 pandas 來處理資料


In [8]:
import pandas

csv 欄位依照手冊設定

國道高速公路電子收費交通資料蒐集支援系統(Traffic Data Collection System,TDCS)使用手冊

  • VehicleType: 車種 31(小客車) 、32(小貨車) 、41(大客車) 、42(大貨車) 、5(聯結車)
  • DetectionTime_O:車輛通過本旅次第 1 個偵測站時間
  • GantryID_O: 車輛通過本旅次第 1 個偵測站編號
  • DetectionTime_D: 車輛通過本旅次最後 1 個偵測站時間
  • GantryID_D: 車輛通過本旅次最後 1 個偵測站編號
  • TripLength:本旅次之行駛距離
  • TripEnd:旅次結標記 (Y:旅次正常結束,N:異常)
  • TripInformation: 本旅次經過的各個偵測站之通過時間及偵測站編號

In [9]:
# 設定欄位名稱
M06A_fields = ['VehicleType',
               'DetectionTime_O','GantryID_O',
               'DetectionTime_D','GantryID_D ',
               'TripLength', 'TripEnd', 'TripInformation']
# 打開裡面 10 點鐘的資料
csv = tar.extractfile(csv_format(hour=10, **data_config))
# 讀進資料
data = pandas.read_csv(csv, names=M06A_fields)

In [10]:
data


Out[10]:
VehicleType DetectionTime_O GantryID_O DetectionTime_D GantryID_D TripLength TripEnd TripInformation
0 31 2016-12-18 10:00:50 01F1045N 2016-12-18 10:29:01 01F0584N 53.400 Y 2016-12-18 10:00:50+01F1045N; 2016-12-18 10:04...
1 31 2016-12-18 10:34:24 01F3525S 2016-12-18 10:46:09 01F3686S 20.200 Y 2016-12-18 10:34:24+01F3525S; 2016-12-18 10:37...
2 31 2016-12-18 10:57:33 03F3854N 2016-12-18 11:15:23 01F3686S 33.600 Y 2016-12-18 10:57:33+03F3854N; 2016-12-18 11:12...
3 31 2016-12-18 10:05:11 03F0525S 2016-12-18 10:07:39 03F0559S 12.100 Y 2016-12-18 10:05:11+03F0525S; 2016-12-18 10:07...
4 31 2016-12-18 10:35:46 01F3185S 2016-12-18 11:05:08 01F3686S 54.100 Y 2016-12-18 10:35:46+01F3185S; 2016-12-18 10:38...
5 31 2016-12-18 10:00:35 03F3496N 2016-12-18 10:03:32 03F3445N 16.800 Y 2016-12-18 10:00:35+03F3496N; 2016-12-18 10:03...
6 32 2016-12-18 10:00:21 05F0287N 2016-12-18 12:40:50 03F0021N 46.600 Y 2016-12-18 10:00:21+05F0287N; 2016-12-18 12:27...
7 31 2016-12-18 10:50:12 01H0271N 2016-12-18 10:55:02 01H0200N 13.300 Y 2016-12-18 10:50:12+01H0271N; 2016-12-18 10:54...
8 31 2016-12-18 10:09:36 01F0339S 2016-12-18 10:16:15 01H0447S 19.400 Y 2016-12-18 10:09:36+01F0339S; 2016-12-18 10:16...
9 32 2016-12-18 10:36:58 01F3696N 2016-12-18 10:43:35 01F3640N 8.000 Y 2016-12-18 10:36:58+01F3696N; 2016-12-18 10:38...
10 31 2016-12-18 10:59:07 03F2985N 2016-12-18 10:59:07 03F2985N 3.000 Y 2016-12-18 10:59:07+03F2985N
11 32 2016-12-18 10:18:38 01F3640N 2016-12-18 10:44:03 01F3525N 18.000 Y 2016-12-18 10:18:38+01F3640N; 2016-12-18 10:21...
12 31 2016-12-18 10:19:12 01F3460N 2016-12-18 10:19:12 01F3460N 7.100 Y 2016-12-18 10:19:12+01F3460N
13 31 2016-12-18 10:07:39 03F2261S 2016-12-18 11:20:08 01F3019S 118.805 Y 2016-12-18 10:07:39+03F2261S; 2016-12-18 10:10...
14 31 2016-12-18 10:25:34 01F0099S 2016-12-18 10:38:24 01H0305S 26.220 Y 2016-12-18 10:25:34+01F0099S; 2016-12-18 10:29...
15 31 2016-12-18 10:26:33 01F0750S 2016-12-18 11:01:52 01F1292S 62.300 Y 2016-12-18 10:26:33+01F0750S; 2016-12-18 10:34...
16 32 2016-12-18 10:32:41 01F0099N 2016-12-18 10:32:41 01F0099N 3.700 Y 2016-12-18 10:32:41+01F0099N
17 31 2016-12-18 10:32:55 05F0438N 2016-12-18 10:49:58 05F0287N 32.000 Y 2016-12-18 10:32:55+05F0438N; 2016-12-18 10:41...
18 31 2016-12-18 10:57:03 03F2125N 2016-12-18 12:55:52 01F0293N 182.900 Y 2016-12-18 10:57:03+03F2125N; 2016-12-18 10:58...
19 31 2016-12-18 10:15:57 01F2089N 2016-12-18 10:27:00 01F1906N 21.600 Y 2016-12-18 10:15:57+01F2089N; 2016-12-18 10:20...
20 31 2016-12-18 10:52:17 03F1992N 2016-12-18 10:59:48 01F2011S 20.200 Y 2016-12-18 10:52:17+03F1992N; 2016-12-18 10:56...
21 31 2016-12-18 10:47:22 05F0438N 2016-12-18 11:35:25 05F0055N 42.700 Y 2016-12-18 10:47:22+05F0438N; 2016-12-18 10:55...
22 42 2016-12-18 10:44:36 01F2322S 2016-12-18 11:50:23 01F2714S 52.800 Y 2016-12-18 10:44:36+01F2322S; 2016-12-18 10:49...
23 31 2016-12-18 10:54:52 01F0413N 2016-12-18 11:07:08 01F0233N 18.300 Y 2016-12-18 10:54:52+01F0413N; 2016-12-18 10:57...
24 31 2016-12-18 10:03:25 01F3590S 2016-12-18 10:08:36 01F3686S 13.400 Y 2016-12-18 10:03:25+01F3590S; 2016-12-18 10:06...
25 31 2016-12-18 10:00:23 01F3696N 2016-12-18 10:00:23 01F3696N 3.000 Y 2016-12-18 10:00:23+01F3696N
26 31 2016-12-18 10:32:18 01F1292N 2016-12-18 11:31:45 01F0293N 105.700 Y 2016-12-18 10:32:18+01F1292N; 2016-12-18 10:41...
27 32 2016-12-18 10:32:47 01F3185N 2016-12-18 10:32:47 01F3185N 4.100 Y 2016-12-18 10:32:47+01F3185N
28 31 2016-12-18 10:59:35 03F4021N 2016-12-18 11:05:05 03F3916N 15.700 Y 2016-12-18 10:59:35+03F4021N; 2016-12-18 11:05...
29 31 2016-12-18 10:17:37 03F4259N 2016-12-18 10:42:59 01F3696N 39.450 Y 2016-12-18 10:17:37+03F4259N; 2016-12-18 10:19...
... ... ... ... ... ... ... ... ...
211217 31 2016-12-18 10:02:20 01F0633S 2016-12-18 10:04:57 01F0681S 6.800 Y 2016-12-18 10:02:20+01F0633S; 2016-12-18 10:04...
211218 31 2016-12-18 10:31:03 03F3392S 2016-12-18 10:31:03 03F3392S 5.300 Y 2016-12-18 10:31:03+03F3392S
211219 31 2016-12-18 10:23:12 01F2011N 2016-12-18 10:35:42 01F1802N 29.100 Y 2016-12-18 10:23:12+01F2011N; 2016-12-18 10:26...
211220 31 2016-12-18 10:31:45 01F2483N 2016-12-18 10:31:45 01F2483N 6.500 Y 2016-12-18 10:31:45+01F2483N
211221 31 2016-12-18 10:59:49 01F3590N 2016-12-18 11:44:26 01F3019N 62.830 Y 2016-12-18 10:59:49+01F3590N; 2016-12-18 11:01...
211222 31 2016-12-18 10:08:06 01F0155N 2016-12-18 10:14:58 01F0061N 11.800 Y 2016-12-18 10:08:06+01F0155N; 2016-12-18 10:08...
211223 31 2016-12-18 10:27:46 01F1664S 2016-12-18 10:32:03 01F1725S 8.700 Y 2016-12-18 10:27:46+01F1664S; 2016-12-18 10:32...
211224 32 2016-12-18 10:34:22 01F2322N 2016-12-18 11:07:19 03F1860N 57.200 Y 2016-12-18 10:34:22+01F2322N; 2016-12-18 10:39...
211225 31 2016-12-18 10:44:07 01F1839S 2016-12-18 11:10:42 01F2249S 54.600 Y 2016-12-18 10:44:07+01F1839S; 2016-12-18 10:48...
211226 31 2016-12-18 10:34:31 01F1774N 2016-12-18 12:37:58 01F0213N 161.800 Y 2016-12-18 10:34:31+01F1774N; 2016-12-18 10:39...
211227 31 2016-12-18 10:13:50 03F0447S 2016-12-18 10:21:26 03F0559S 19.700 Y 2016-12-18 10:13:50+03F0447S; 2016-12-18 10:19...
211228 31 2016-12-18 10:15:02 03F0338N 2016-12-18 10:32:39 05F0055S 34.300 Y 2016-12-18 10:15:02+03F0338N; 2016-12-18 10:17...
211229 31 2016-12-18 10:03:44 03F2194N 2016-12-18 10:07:36 03F2125N 11.200 Y 2016-12-18 10:03:44+03F2194N; 2016-12-18 10:07...
211230 31 2016-12-18 10:50:27 01F0509N 2016-12-18 11:07:20 01F0256N 27.400 Y 2016-12-18 10:50:27+01F0509N; 2016-12-18 10:53...
211231 31 2016-12-18 10:40:34 01F0155S 2016-12-18 10:46:52 01F0248S 9.900 Y 2016-12-18 10:40:34+01F0155S; 2016-12-18 10:42...
211232 31 2016-12-18 10:42:09 01F3286N 2016-12-18 11:20:08 01F2827N 57.800 Y 2016-12-18 10:42:09+01F3286N; 2016-12-18 10:44...
211233 31 2016-12-18 10:04:45 01F2011S 2016-12-18 10:45:49 01F2674S 72.000 Y 2016-12-18 10:04:45+01F2011S; 2016-12-18 10:09...
211234 31 2016-12-18 10:54:48 03F0087S 2016-12-18 11:10:55 03F0337S 33.500 Y 2016-12-18 10:54:48+03F0087S; 2016-12-18 10:56...
211235 31 2016-12-18 10:07:06 01F0376N 2016-12-18 10:15:07 01F0256N 16.400 Y 2016-12-18 10:07:06+01F0376N; 2016-12-18 10:09...
211236 31 2016-12-18 10:28:48 01F3083S 2016-12-18 10:59:01 01F3590S 58.700 Y 2016-12-18 10:28:48+01F3083S; 2016-12-18 10:31...
211237 41 2016-12-18 10:11:58 03F0337S 2016-12-18 10:19:36 03F0447S 19.500 Y 2016-12-18 10:11:58+03F0337S; 2016-12-18 10:15...
211238 31 2016-12-18 10:57:09 01F0061N 2016-12-18 10:57:09 01F0061N 1.800 Y 2016-12-18 10:57:09+01F0061N
211239 31 2016-12-18 10:19:51 03F1651S 2016-12-18 10:52:50 03F2129S 49.800 Y 2016-12-18 10:19:51+03F1651S; 2016-12-18 10:23...
211240 31 2016-12-18 10:58:58 01F3366S 2016-12-18 11:17:58 01F3686S 38.900 Y 2016-12-18 10:58:58+01F3366S; 2016-12-18 11:00...
211241 31 2016-12-18 10:16:37 01F2156N 2016-12-18 10:25:06 01F2011N 21.700 Y 2016-12-18 10:16:37+01F2156N; 2016-12-18 10:20...
211242 31 2016-12-18 10:49:57 03F0648N 2016-12-18 10:49:57 03F0648N 5.600 Y 2016-12-18 10:49:57+03F0648N
211243 31 2016-12-18 10:31:51 01F0376N 2016-12-18 10:40:41 01F0256N 16.400 Y 2016-12-18 10:31:51+01F0376N; 2016-12-18 10:34...
211244 31 2016-12-18 10:31:30 03F0846N 2016-12-18 10:31:30 03F0846N 11.000 Y 2016-12-18 10:31:30+03F0846N
211245 31 2016-12-18 10:38:09 03F3854S 2016-12-18 10:38:09 03F3854S 8.600 Y 2016-12-18 10:38:09+03F3854S
211246 31 2016-12-18 10:44:36 01F0633S 2016-12-18 10:44:36 01F0633S 2.600 Y 2016-12-18 10:44:36+01F0633S

211247 rows × 8 columns


In [11]:
# 先檢查一下有沒有異常的資料
data[data.TripEnd == 'N'].shape


Out[11]:
(0, 8)

In [12]:
# 先去除異常資料
data = data[data.TripEnd == 'Y']

In [13]:
# 然後乾脆刪掉 TripEnd 這欄
del data['TripEnd']
# 也可以用 data.drop('TripEnd', axis=1, inplace=True)

查看一下內容


In [14]:
# 前 5 筆
# 或 data.iloc[:5]
data.head(5)


Out[14]:
VehicleType DetectionTime_O GantryID_O DetectionTime_D GantryID_D TripLength TripInformation
0 31 2016-12-18 10:00:50 01F1045N 2016-12-18 10:29:01 01F0584N 53.4 2016-12-18 10:00:50+01F1045N; 2016-12-18 10:04...
1 31 2016-12-18 10:34:24 01F3525S 2016-12-18 10:46:09 01F3686S 20.2 2016-12-18 10:34:24+01F3525S; 2016-12-18 10:37...
2 31 2016-12-18 10:57:33 03F3854N 2016-12-18 11:15:23 01F3686S 33.6 2016-12-18 10:57:33+03F3854N; 2016-12-18 11:12...
3 31 2016-12-18 10:05:11 03F0525S 2016-12-18 10:07:39 03F0559S 12.1 2016-12-18 10:05:11+03F0525S; 2016-12-18 10:07...
4 31 2016-12-18 10:35:46 01F3185S 2016-12-18 11:05:08 01F3686S 54.1 2016-12-18 10:35:46+01F3185S; 2016-12-18 10:38...

In [15]:
# 第  12 筆
data.iloc[11]


Out[15]:
VehicleType                                                       32
DetectionTime_O                                  2016-12-18 10:18:38
GantryID_O                                                  01F3640N
DetectionTime_D                                  2016-12-18 10:44:03
GantryID_D                                                  01F3525N
TripLength                                                        18
TripInformation    2016-12-18 10:18:38+01F3640N; 2016-12-18 10:21...
Name: 11, dtype: object

In [20]:
# 對我們來說,其實重要的只有 TripInformation 和 VehicleType
# 先只注意這兩項
data = data[['VehicleType', "TripInformation"]]
data.head(5)


Out[20]:
VehicleType TripInformation
0 31 2016-12-18 10:00:50+01F1045N; 2016-12-18 10:04...
1 31 2016-12-18 10:34:24+01F3525S; 2016-12-18 10:37...
2 31 2016-12-18 10:57:33+03F3854N; 2016-12-18 11:12...
3 31 2016-12-18 10:05:11+03F0525S; 2016-12-18 10:07...
4 31 2016-12-18 10:35:46+01F3185S; 2016-12-18 10:38...

In [23]:
# 查看看小貨車資料
data.query('VehicleType==32')


Out[23]:
VehicleType TripInformation
6 32 2016-12-18 10:00:21+05F0287N; 2016-12-18 12:27...
9 32 2016-12-18 10:36:58+01F3696N; 2016-12-18 10:38...
11 32 2016-12-18 10:18:38+01F3640N; 2016-12-18 10:21...
16 32 2016-12-18 10:32:41+01F0099N
27 32 2016-12-18 10:32:47+01F3185N
35 32 2016-12-18 10:47:00+01F3286N
41 32 2016-12-18 10:33:12+03F0337S; 2016-12-18 10:37...
51 32 2016-12-18 10:19:00+03A0041N
73 32 2016-12-18 10:08:37+05F0528N; 2016-12-18 10:15...
82 32 2016-12-18 10:21:55+01F0467N
102 32 2016-12-18 10:18:46+03F2194N; 2016-12-18 10:21...
113 32 2016-12-18 10:45:24+03A0015S; 2016-12-18 10:47...
132 32 2016-12-18 10:57:22+01F0061S; 2016-12-18 10:59...
135 32 2016-12-18 10:30:40+03F1215S; 2016-12-18 10:32...
138 32 2016-12-18 10:27:27+03A0015S
139 32 2016-12-18 10:41:46+01F0532N; 2016-12-18 10:45...
142 32 2016-12-18 10:10:06+01F2930S; 2016-12-18 10:15...
148 32 2016-12-18 10:31:12+03F0525S
151 32 2016-12-18 10:37:33+01F3696N; 2016-12-18 10:38...
153 32 2016-12-18 10:44:38+01F0339S; 2016-12-18 10:51...
178 32 2016-12-18 10:56:22+03F0116N; 2016-12-18 10:59...
189 32 2016-12-18 10:54:31+03F1633N; 2016-12-18 11:03...
191 32 2016-12-18 10:20:16+01F0681N; 2016-12-18 10:21...
192 32 2016-12-18 10:54:01+03F0006S; 2016-12-18 10:59...
198 32 2016-12-18 10:03:22+01F0681N; 2016-12-18 10:04...
217 32 2016-12-18 10:07:19+01F2866N; 2016-12-18 10:09...
240 32 2016-12-18 10:06:14+01F3686S
252 32 2016-12-18 10:58:26+01F0681N; 2016-12-18 10:59...
260 32 2016-12-18 10:56:35+01F2425S; 2016-12-18 11:00...
266 32 2016-12-18 10:27:24+03F0394S; 2016-12-18 10:31...
... ... ...
211001 32 2016-12-18 10:46:54+01F1774N; 2016-12-18 10:51...
211010 32 2016-12-18 10:30:57+03F2129S
211013 32 2016-12-18 10:59:17+01H0579N; 2016-12-18 11:06...
211016 32 2016-12-18 10:44:40+03F4232N; 2016-12-18 10:48...
211020 32 2016-12-18 10:58:05+01F1664S; 2016-12-18 11:01...
211043 32 2016-12-18 10:09:03+03F3854S; 2016-12-18 10:12...
211045 32 2016-12-18 10:48:59+01F3676S; 2016-12-18 10:49...
211048 32 2016-12-18 10:58:02+03F2231N; 2016-12-18 11:00...
211051 32 2016-12-18 10:49:30+03F3854N; 2016-12-18 10:55...
211052 32 2016-12-18 10:32:05+01F2249N; 2016-12-18 10:36...
211056 32 2016-12-18 10:44:46+01F0467N
211063 32 2016-12-18 10:07:49+01H0206S; 2016-12-18 10:13...
211087 32 2016-12-18 10:32:47+03F0525S
211094 32 2016-12-18 10:38:25+03F0559S
211102 32 2016-12-18 10:13:04+01F0557N; 2016-12-18 10:14...
211111 32 2016-12-18 10:58:47+01F0633S; 2016-12-18 11:00...
211122 32 2016-12-18 10:17:19+01F3696N; 2016-12-18 10:18...
211132 32 2016-12-18 10:09:31+05F0287N; 2016-12-18 10:35...
211146 32 2016-12-18 10:05:20+01F0233N; 2016-12-18 10:06...
211147 32 2016-12-18 10:27:44+01F3366S
211150 32 2016-12-18 10:29:16+03F2614N; 2016-12-18 10:33...
211176 32 2016-12-18 10:57:04+01F3696N; 2016-12-18 10:58...
211177 32 2016-12-18 10:13:31+01F0376N; 2016-12-18 10:15...
211178 32 2016-12-18 10:14:28+03F0116N; 2016-12-18 10:18...
211189 32 2016-12-18 10:02:20+03F1944S; 2016-12-18 10:04...
211195 32 2016-12-18 10:02:16+03F0158S; 2016-12-18 10:05...
211201 32 2016-12-18 10:06:08+01F0339S
211202 32 2016-12-18 10:33:47+03F3588N
211215 32 2016-12-18 10:12:06+01F3460S; 2016-12-18 10:16...
211224 32 2016-12-18 10:34:22+01F2322N; 2016-12-18 10:39...

33815 rows × 2 columns


In [25]:
# 或者查看看小客車資料
data[data.VehicleType==31]


Out[25]:
VehicleType TripInformation
0 31 2016-12-18 10:00:50+01F1045N; 2016-12-18 10:04...
1 31 2016-12-18 10:34:24+01F3525S; 2016-12-18 10:37...
2 31 2016-12-18 10:57:33+03F3854N; 2016-12-18 11:12...
3 31 2016-12-18 10:05:11+03F0525S; 2016-12-18 10:07...
4 31 2016-12-18 10:35:46+01F3185S; 2016-12-18 10:38...
5 31 2016-12-18 10:00:35+03F3496N; 2016-12-18 10:03...
7 31 2016-12-18 10:50:12+01H0271N; 2016-12-18 10:54...
8 31 2016-12-18 10:09:36+01F0339S; 2016-12-18 10:16...
10 31 2016-12-18 10:59:07+03F2985N
12 31 2016-12-18 10:19:12+01F3460N
13 31 2016-12-18 10:07:39+03F2261S; 2016-12-18 10:10...
14 31 2016-12-18 10:25:34+01F0099S; 2016-12-18 10:29...
15 31 2016-12-18 10:26:33+01F0750S; 2016-12-18 10:34...
17 31 2016-12-18 10:32:55+05F0438N; 2016-12-18 10:41...
18 31 2016-12-18 10:57:03+03F2125N; 2016-12-18 10:58...
19 31 2016-12-18 10:15:57+01F2089N; 2016-12-18 10:20...
20 31 2016-12-18 10:52:17+03F1992N; 2016-12-18 10:56...
21 31 2016-12-18 10:47:22+05F0438N; 2016-12-18 10:55...
23 31 2016-12-18 10:54:52+01F0413N; 2016-12-18 10:57...
24 31 2016-12-18 10:03:25+01F3590S; 2016-12-18 10:06...
25 31 2016-12-18 10:00:23+01F3696N
26 31 2016-12-18 10:32:18+01F1292N; 2016-12-18 10:41...
28 31 2016-12-18 10:59:35+03F4021N; 2016-12-18 11:05...
29 31 2016-12-18 10:17:37+03F4259N; 2016-12-18 10:19...
30 31 2016-12-18 10:08:44+01F0248S; 2016-12-18 10:09...
31 31 2016-12-18 10:01:20+01H0206S; 2016-12-18 10:07...
32 31 2016-12-18 10:16:13+01H0271N
33 31 2016-12-18 10:56:15+01H0305S; 2016-12-18 10:58...
34 31 2016-12-18 10:35:09+03F1332S; 2016-12-18 10:38...
36 31 2016-12-18 10:22:44+01H0305S; 2016-12-18 10:25...
... ... ...
211214 31 2016-12-18 10:30:44+01F3019N; 2016-12-18 10:36...
211216 31 2016-12-18 10:57:20+03F0447S; 2016-12-18 11:03...
211217 31 2016-12-18 10:02:20+01F0633S; 2016-12-18 10:04...
211218 31 2016-12-18 10:31:03+03F3392S
211219 31 2016-12-18 10:23:12+01F2011N; 2016-12-18 10:26...
211220 31 2016-12-18 10:31:45+01F2483N
211221 31 2016-12-18 10:59:49+01F3590N; 2016-12-18 11:01...
211222 31 2016-12-18 10:08:06+01F0155N; 2016-12-18 10:08...
211223 31 2016-12-18 10:27:46+01F1664S; 2016-12-18 10:32...
211225 31 2016-12-18 10:44:07+01F1839S; 2016-12-18 10:48...
211226 31 2016-12-18 10:34:31+01F1774N; 2016-12-18 10:39...
211227 31 2016-12-18 10:13:50+03F0447S; 2016-12-18 10:19...
211228 31 2016-12-18 10:15:02+03F0338N; 2016-12-18 10:17...
211229 31 2016-12-18 10:03:44+03F2194N; 2016-12-18 10:07...
211230 31 2016-12-18 10:50:27+01F0509N; 2016-12-18 10:53...
211231 31 2016-12-18 10:40:34+01F0155S; 2016-12-18 10:42...
211232 31 2016-12-18 10:42:09+01F3286N; 2016-12-18 10:44...
211233 31 2016-12-18 10:04:45+01F2011S; 2016-12-18 10:09...
211234 31 2016-12-18 10:54:48+03F0087S; 2016-12-18 10:56...
211235 31 2016-12-18 10:07:06+01F0376N; 2016-12-18 10:09...
211236 31 2016-12-18 10:28:48+01F3083S; 2016-12-18 10:31...
211238 31 2016-12-18 10:57:09+01F0061N
211239 31 2016-12-18 10:19:51+03F1651S; 2016-12-18 10:23...
211240 31 2016-12-18 10:58:58+01F3366S; 2016-12-18 11:00...
211241 31 2016-12-18 10:16:37+01F2156N; 2016-12-18 10:20...
211242 31 2016-12-18 10:49:57+03F0648N
211243 31 2016-12-18 10:31:51+01F0376N; 2016-12-18 10:34...
211244 31 2016-12-18 10:31:30+03F0846N
211245 31 2016-12-18 10:38:09+03F3854S
211246 31 2016-12-18 10:44:36+01F0633S

168197 rows × 2 columns